﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ndo.Maths
{
    public class DoubleFloat : Real<DoubleFloat>
    {
        public DoubleFloat()
        : this(1)
        { }
        public DoubleFloat(Double f)
        {
            value = f;
        }

        public override bool IsNaN
        { get { return Double.IsNaN(value); } }
        public override bool IsPositiveInfinity
        { get { return Double.IsPositiveInfinity(value); } }
        public override bool IsNegativeInfinity
        { get { return Double.IsNegativeInfinity(value); } }

        private readonly Double value;
        public static explicit operator Double(DoubleFloat i)
        {
            return i.value;
        }
        public static implicit operator DoubleFloat(Double i)
        {
            return new DoubleFloat(i);
        }
        public static DoubleFloat operator +(DoubleFloat i1, DoubleFloat i2)
        {
            return new DoubleFloat((Double)(i1.value + i2.value));
        }
        public static DoubleFloat operator -(DoubleFloat i1, DoubleFloat i2)
        {
            return new DoubleFloat((Double)(i1.value - i2.value));
        }
        public static DoubleFloat operator *(DoubleFloat i1, DoubleFloat i2)
        {
            return new DoubleFloat((Double)(i1.value * i2.value));
        }
        public static DoubleFloat operator /(DoubleFloat i1, DoubleFloat i2)
        {
            return new DoubleFloat((Double)(i1.value / i2.value));
        }
        public static DoubleFloat operator %(DoubleFloat i1, DoubleFloat i2)
        {
            return new DoubleFloat((Double)(i1.value % i2.value));
        }
        public static bool operator ==(DoubleFloat i1, DoubleFloat i2)
        {
            return i1.value == i2.value;
        }
        public static bool operator !=(DoubleFloat i1, DoubleFloat i2)
        {
            return i1.value != i2.value;
        }

        public override bool Equals(object obj)
        {
            if (obj is DoubleFloat)
                return this.value == ((DoubleFloat)obj).value;
            return false;
        }
        public override int GetHashCode()
        {
            return value.GetHashCode();
        }
        public override string ToString()
        {
            return value.ToString();
        }

        public override int CompareTo(DoubleFloat other)
        {
            return value.CompareTo(other.value);
        }

        public override SignTypes Sign
        {
            get
            {
                if (value > 0)
                    return SignTypes.Positive;
                if (value < 0)
                    return SignTypes.Negative;
                return SignTypes.Zero;
            }
        }
    }
}
